<?php
class XA_XHTML_Panel_User extends XA_XHTML {


	public function __construct($id = null) {
		parent::__construct($id);
		$this->class_list = array('panel', 'user');
	}


	public function out() {
		flush();
		ob_start();
		$user = $GLOBALS['user'];
		?>
		<div <?= $this->id ? 'id="'.$this->id.'"' : '' ?> class="<?= implode(' ', $this->class_list) ?>">
			<?php
			if ($user->id) {
				?>
				<div class="details">
					Zalogowany(a) jako <span class="name"><?= $user->get('name') ?></span>.
				</div>
				<form class="login" action="<?= xa::url('action=logout_handle') ?>" method="post">
					<p>
						<input class="button" type="submit" value="Wyloguj" />
					</p>
				</form>
				<?php
			} else {
				if (AUTH_BASIC) {
					?>
					<form class="login" action="<?= xa::url('action=login_handle') ?>" method="post">
						<p class="login">
							<label for="login_form_login_input">Login</label>
							<input type="text" name="login" id="login_form_login_input" />
						</p>
						<p class="password">
							<label for="login_form_password_input">Hasło</label>
							<input type="password" name="password" id="login_form_password_input" />
						</p>
						<p class="submit">
							<input type="submit" value="Zaloguj" />
						</p>
					</form>
					<div class="options">
						<a href="<?= xa::url('action=account_create') ?>">Załóż konto</a>
						<a href="<?= xa::url('action=password_remind') ?>">Przypomnij hasło</a>
					</div>
					<?php
				}
				if (AUTH_FB) {
					$scope = empty($GLOBALS['fb_auth_scope']) ? array('email') : $GLOBALS['fb_auth_scope'];
					?>
					<a class="facebook" href="https://www.facebook.com/dialog/oauth?client_id=<?= FB_APP_ID ?>&amp;response_type=token&amp;scope=<?= implode(',', $scope) ?>&amp;redirect_uri=<?= urlencode(xa::url('action=login_handle')) ?>" title="Zaloguj przez Facebook"><img alt="Zaloguj przez Facebook" src="<?= SITE_URL ?>img/fb_login.png" /></a>
					<?php
				}
			}
			?>
		</div>
		<?php
		$return = ob_get_contents();
		ob_end_clean();

		return $return;
	}
}
